<?php
class City_model extends CI_Model {
	
	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    
    public function find_all_province() {
    	$results = $this->db->get("province")->result_array();
    	$provinces = array('0' => '不限');
    	foreach ($results as $row) {
    		$provinces[$row['provinceID']] = $row['province'];
    	}
    	return $provinces;
    }
	
    public function find_all_cities($province_id) {
    	$this->db->where("fatherID", intval($province_id));
    	$results = $this->db->get("city")->result_array();
    	$cities = array();
    	foreach ($results as $row) {
    		$cities[$row['cityID']] = $row['city'];
    	}
    	return $cities;
    }
    
    public function find_all_areas($city_id) {
    	$this->db->where("fatherID", intval($city_id));
    	$results = $this->db->get("area")->result_array();
    	$areas = array();
    	foreach ($results as $row) {
    		$areas[$row['areaID']] = $row['area'];
    	}
    	return $areas;
    }
    
    public function find_cities_by_ids($ids) {
    	$sql = "select * from city where cityID in (" . implode(",", $ids) . ")";
    	$results = $this->db->query($sql)->result_array();
    	$cities = array();
    	foreach ($results as $row) {
    		$cities[$row['cityID']] = $row['city'];
    	}
    	return $cities;
    }
    
     public function find_areas_by_ids($ids) {
    	$sql = "select * from area where areaID in (" . implode(",", $ids) . ")";
    	$results = $this->db->query($sql)->result_array();
    	$areas = array();
    	foreach ($results as $row) {
    		$areas[$row['areaID']] = $row['area'];
    	}
    	return $areas;
     }
}